package cc.miwuya.property.controller;

import cc.miwuya.common.util.Result;
import cc.miwuya.core.BaseController;
import cc.miwuya.property.domain.CommonLight;
import cc.miwuya.property.service.CommonLightService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @Author 迷雾森林
 * @Date 2024-02-27 14:53
 * @Desc 公共照明控制器
 */
@RestController
@RequestMapping("/property/commonLight")
public class CommonLightController extends BaseController {

    @Resource
    CommonLightService commonLightService;

    @PostMapping("/edit")
    public Result edit(@RequestBody CommonLight commonLight){
        return Result.success(commonLightService.saveOrUpdate(commonLight));
    }
    @GetMapping("/list/{residentialId}")
    public Result list(@PathVariable Long residentialId){

        return Result.success(commonLightService.getPage(getPage(),residentialId));
    }
    @GetMapping("/info/{commonLightId}")
    public Result info(@PathVariable Long commonLightId){
        return Result.success(commonLightService.getById(commonLightId));
    }
    @GetMapping("/replace/{lightId}")
    public Result replace(@PathVariable Long lightId){
        CommonLight light;
        CommonLight oldLight = new CommonLight();
        light = commonLightService.getById(lightId);
        oldLight = light;
        light.setId(null);
        commonLightService.save(light);
        oldLight.setDamageTime(LocalDateTime.now());
        oldLight.setReplaceId(light.getId());
        oldLight.setId(lightId);
        commonLightService.updateById(oldLight);
        return Result.success();
    }
    @GetMapping("/getCommonLightTime")
    public Object getCommonLightTime(){
        return commonLightService.getCommonLightTime();
    }
}
